package de.akabahn.ebd.control.comm;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Peter Eimann
 */
public class TfzInfo {

	private String tfz;
	private List<Integer> speedList;
	private String type;
	private int maxSpeed;
	private int funcPfeifen;
	private int funcTueren;

	/**
	 * @param tfzInfoString
	 * @return
	 */
	public static TfzInfo unmarshal(String tfz, String tfzInfoString) {
		// Response-Format: OK (<V5>,<V10>,<V15>.....<V240>/TYP/HG/PFEI/TUER)
		if (tfzInfoString != null && tfzInfoString.startsWith("OK (")) {
			String[] segments = tfzInfoString.substring(4, tfzInfoString.length() - 1).split("/");
			TfzInfo tfzInfo = new TfzInfo();
			tfzInfo.setTfz(tfz);
			List<Integer> speedList = new ArrayList<Integer>();
			speedList.add(0);
			for (String speed : segments[0].split(",")) {
				speedList.add(Integer.decode(speed));
			}
			tfzInfo.setSpeedList(speedList);
			tfzInfo.setType(segments[1]);
			tfzInfo.setMaxSpeed(Integer.parseInt(segments[2]));
			tfzInfo.setFuncPfeifen("*".equals(segments[3]) ? -1 :  Integer.parseInt(segments[3]));
			tfzInfo.setFuncTueren("*".equals(segments[4]) ? -1 :  Integer.parseInt(segments[4]));

			return tfzInfo;
		}

		return null;
	}

	/**
	 * @return the tfz
	 */
	public String getTfz() {
		return tfz;
	}

	/**
	 * @return the speedList
	 */
	public List<Integer> getSpeedList() {
		return speedList;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @return the maxSpeed
	 */
	public int getMaxSpeed() {
		return maxSpeed;
	}

	/**
	 * @return the funcPfeifen
	 */
	public int getFuncPfeifen() {
		return funcPfeifen;
	}

	/**
	 * @return the funcTueren
	 */
	public int getFuncTueren() {
		return funcTueren;
	}

	/**
	 * @param tfz the tfz to set
	 */
	void setTfz(String tfz) {
		this.tfz = tfz;
	}

	/**
	 * @param speedList the speedList to set
	 */
	void setSpeedList(List<Integer> speedList) {
		this.speedList = speedList;
	}

	/**
	 * @param type the type to set
	 */
	void setType(String type) {
		this.type = type;
	}

	/**
	 * @param maxSpeed the maxSpeed to set
	 */
	void setMaxSpeed(int maxSpeed) {
		this.maxSpeed = maxSpeed;
	}

	/**
	 * @param funcPfeifen the funcPfeifen to set
	 */
	void setFuncPfeifen(int funcPfeifen) {
		this.funcPfeifen = funcPfeifen;
	}

	/**
	 * @param funcTueren the funcTueren to set
	 */
	void setFuncTueren(int funcTueren) {
		this.funcTueren = funcTueren;
	}

}
